#include "head.h"

// 菜单信息 - 登陆用
const wchar_t *title = L"普通用户菜单";
const wchar_t *option_1[] = {L"登录", L"注册", L"返回"};

// 系统初始化
FlightSystem Sys_init(void)
{
    FlightSystem Flight_sys;
    Flight_sys.Flight_list = init_double_link_list(); // 航空信息链表
    Flight_sys.ADMIN_USER = init_link_list();         // 管理员链表
    Flight_sys.REGULAR_USER = init_link_list();       // 普通用户链表
    Flight_sys.SILVER_USER = init_link_list();        // 银卡会员链表
    Flight_sys.GOLD_USER = init_link_list();          // 金卡会员链表
    Flight_sys.PLATINUM_USER = init_link_list();      // 白金会员链表
    sort_double_lin_list();
    // 从文件中导入数据
    F_scanf_M(Flight_sys.Flight_list, FLIGHTS_FILE);
    F_scanf(Flight_sys.ADMIN_USER, ADMIN_FILE);
    F_scanf(Flight_sys.REGULAR_USER, REGULAR_FILE);
    F_scanf(Flight_sys.SILVER_USER, SILVER_FILE);
    F_scanf(Flight_sys.GOLD_USER, GOLD_FILE);
    F_scanf(Flight_sys.PLATINUM_USER, PLATINUM_FILE);

    return Flight_sys;
}
// 登录或是注册
void sys_login(FlightSystem Flight_sys)
{
    while (1)
    {
        int flag = 0;
        flag = display_menu(title, option_1, 3);
        user_t data_2;
        u_f_data d;
        data_2.ticket = &d;
        Init_Sql_List(data_2.ticket);
        switch (flag)
        {
        case 1:
            data_2 = loog_in_link(Flight_sys); // 用于接收登录函数返回的数据，判断用户人员
            data_2.ticket = &d;
            Init_Sql_List(data_2.ticket);
            if (1 != data_2.IDcard)
            {
                U_menu(Flight_sys, data_2);
            }
            else
            {
                M_menu(Flight_sys, data_2);
            }
            break;
        case 2:
            zc(Flight_sys.REGULAR_USER);
            break;
        default:
            exit(-1);
            break;
            sys_exit(Flight_sys);
        }
    }
}
// 系统退出
void sys_exit(FlightSystem Flight_sys)
{
    
    F_print(Flight_sys.REGULAR_USER, REGULAR_FILE);
    F_print(Flight_sys.SILVER_USER, SILVER_FILE);
    F_print(Flight_sys.GOLD_USER, GOLD_FILE);
    F_print(Flight_sys.PLATINUM_USER, PLATINUM_FILE);
    F_print_M(Flight_sys.Flight_list, FLIGHTS_FILE);

    free_double_link_list(&Flight_sys.Flight_list);
    free_link_list(&Flight_sys.ADMIN_USER);
    free_link_list(&Flight_sys.REGULAR_USER);
    free_link_list(&Flight_sys.SILVER_USER);
    free_link_list(&Flight_sys.GOLD_USER);
    free_link_list(&Flight_sys.PLATINUM_USER);
}